const NOW_USER = 'NOW_USER'
const NOW_SHOP = 'NOW_SHOP'
const NOW_STORE = 'NOW_STORE'
const NOW_ADDRESS_PREDIX = 'NOW_ADDRESS_PREDIX'
const SHOPPING_CART = 'SHOPPING_CART'

class LocalStorageService {
  getNowUser() {
    let result = JSON.parse(window.localStorage.getItem(NOW_USER))
    if (result === null || result === undefined) {
      result = null
    }
    return result
  }
  setNowUser(nowUser) {
    if (nowUser === null) {
      window.localStorage.removeItem(NOW_USER)
    } else {
      window.localStorage.setItem(NOW_USER, JSON.stringify(nowUser))
    }
  }
  getNowShop() {
    let result = JSON.parse(window.localStorage.getItem(NOW_SHOP))
    if (result === null || result === undefined) {
      result = null
    }
    return result
  }
  setNowShop(nowShop) {
    if (nowShop === null) {
      window.localStorage.removeItem(NOW_SHOP)
    } else {
      window.localStorage.setItem(NOW_SHOP, JSON.stringify(nowShop))
    }
  }
  getNowStore() {
    let result = JSON.parse(window.localStorage.getItem(NOW_STORE))
    if (result === null || result === undefined) {
      result = null
    }
    return result
  }
  setNowStore(nowStore) {
    if (nowStore === null) {
      window.localStorage.removeItem(NOW_STORE)
    } else {
      window.localStorage.setItem(NOW_STORE, JSON.stringify(nowStore))
    }
  }
  getNowAddressPredix() {
    let result = JSON.parse(window.localStorage.getItem(NOW_ADDRESS_PREDIX))
    if (result === null || result === undefined) {
      result = null
    }
    return result
  }
  setNowAddressPredix(nowAddressPredix) {
    if (nowAddressPredix === null) {
      window.localStorage.removeItem(NOW_ADDRESS_PREDIX)
    } else {
      window.localStorage.setItem(
        NOW_ADDRESS_PREDIX,
        JSON.stringify(nowAddressPredix)
      )
    }
  }
  getShoppingCart() {
    let result = JSON.parse(window.localStorage.getItem(SHOPPING_CART))
    if (result === null || result === undefined) {
      result = null
    }
    return result
  }
  setShoppingCart(shoppingCart) {
    if (shoppingCart === null) {
      window.localStorage.removeItem(SHOPPING_CART)
    } else {
      window.localStorage.setItem(
        SHOPPING_CART,
        JSON.stringify(shoppingCart)
      )
    }
  }
}

export default new LocalStorageService()
